<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .menu{
            width: 400px;
            display: flex;
        }
        .menu .item{
            flex: 1;
            text-align: center;
            line-height: 40px;
            background-color: black;
            color: white
        }
        .menu .active{
            color: red;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="menu">
            <div class="item" v-for="item in list" :class="{active:activeIndex==item.id}" @click="change(item)">{{item.msg}}</div>  
            <!-- 点谁谁有样式 其他没有样式 -->
        </div>

    </div>
</body>
<script>
    new  Vue({
        el:"#app",
        data:{
            activeIndex:1,//表示选中的id
            list:[{id:1,msg:"菜单一"},{id:2,msg:"菜单二"},{id:3,msg:"菜单三"},{id:4,msg:"菜单四"}]
        },
        methods:{
            change(item){
                // alert(item.id);
                this.activeIndex = item.id;
            }
        }

    })

</script>
</html>